package org.fatmansoft.teach.service;

import org.fatmansoft.teach.entity.ViewEntity.Student;
import org.fatmansoft.teach.Repository.ViewRepository.StudentRepository;
import org.fatmansoft.teach.util.DateTimeTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TestService {
    @Autowired
    private StudentRepository studentRepository;

    public void createStudent() {
//        创建一个学生
        Student s;
        Integer id = studentRepository.getMaxId();
        if (id == null)
            id = 1;
        else
            id = id + 1;
        s = new Student();
        s.setId(id);
        s.setStudentName("张三");
        s.setSex("男");
        s.setAge(12);
        s.setBirthday(new Date());
        studentRepository.save(s);
    }

    public void testDelete() {
        Student s = studentRepository.findById(1).get();
        System.out.println(DateTimeTool.parseDateTime(s.getBirthday(), "yyyy-MM-dd"));
        studentRepository.delete(s);
    }

    public void testMain() {
//        createStudent();
//        testDelete();
    }
}
